package com.cb.vod.controller;

import com.cb.utils.R;
import com.cb.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author cb
 * @version 1.0
 * @date 2020/6/25 16:14
 */
@Api(description = "视频点播管理")

@RestController
@RequestMapping("/vodservice/video")
public class VodController {

    private final VodService vodService;

    @Autowired
    public VodController(VodService vodService) {
        this.vodService = vodService;
    }

    @ApiOperation("上传视频到阿里云")
    @PostMapping("uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file){
        String videoId = vodService.uploadVideoAliyun(file);

        return R.ok().data("videoId", videoId);
    }

    @ApiOperation("根据视频id删除阿里云视频")
    @DeleteMapping("removeAliyunVideo/{id}")
    public R removeAliyunVideo(@PathVariable String id){
        vodService.removeVideoAliyun(id);

        return R.ok();
    }

    @ApiOperation("根据视频id删除多个阿里云视频")
    @DeleteMapping("removeBatchAliyunVideo")
    public R removeBatchAliyunVideo(
            @ApiParam(name="videoIdList",value = "云端视频id集合",required = true)
            @RequestParam("videoIdList") List<String> videoIdList){
        vodService.removeBatchAliyunVideo(videoIdList);

        return R.ok();
    }

    @ApiOperation("根据视频id获取播放凭证")
    @GetMapping("getPlayAuth/{videoId}")
    public R getPlayAuth(@PathVariable("videoId") String videoId){
        String playAuth = vodService.getPlayAuthByVideoId(videoId);

        return R.ok().data("playAuth", playAuth);
    }

}
